{include file='public/head' /}
{include file='public/left' /}
    <div class="main" style="padding:10px;">
        <div class="content">
            <span>商品列表</span>
            <button class="layui-btn  layui-btn-sm" onclick="add()">添加</button>
            <div></div>
        </div>
        <table class="layui-table">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>商品名称</th>
                    <th>父类ID</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                {volist name='cat' id='cat_v'}
                    <tr>
                        <td>{$cat_v.id}</td>
                        <td>{$cat_v.name}</td>
                        <td>{$cat_v.pid}</td>
                        <td>{if $cat_v.status==1}开启{else/}关闭{/if}</td>
                        <td><button class="layui-btn layui-btn-xs" 
                            onclick="edit({$cat_v.id})">修改</button>
                            <button class="layui-btn layui-btn-xs layui-btn-danger" 
                            onclick="del({$cat_v.id})">删除</button></td>
                    </tr>
                {/volist}
            </tbody>
        </table>
    </div>
    <script type="text/javascript">
	function add(){
            layer.open({
            title: '添加',
            type:2,
            shade:0.3,
            area:['480px','440px'],
            content: '/admin/category/add'
        });  
    }
    function del(id){
        layer.confirm('确定要删除吗？', {
            icon:3,
            btn: ['确定','取消']
        }, function(){
            $.post('/admin/category/del',{'id':id},function(res){
                if(res.code>0){
                    layer.alert(res.msg,{icon:2});
                }else{
                    layer.msg(res.msg);
                    setTimeout(function(){window.location.reload();},1000);
                }
            },'json');
        });
    }
    function edit(id){
        layer.open({
            title: '修改',
            type:2,
            shade:0.3,
            area:['480px','440px'],
            content: '/admin/category/edit?id='+id
        });  
    }
    </script>
{include file='public/bottom' /}